#include "Entity.h"


Entity::Entity(void)
{
	parent = NULL;
}


Entity::~Entity(void)
{
}

void Entity::update(float dt){
	for(int i = 0; i < children.size(); ++i){
		children[i]->update(dt);
	}
}

void Entity::addChild(Entity* ent){
	ent->parent=this;
	children.push_back(ent);
}

bool Entity::destroyChild(Entity* ent){
	for(int i = 0; i < children.size(); ++i){
		if(children[i] == ent){
			delete children[i];
			children.erase(children.begin()+i);
			return true;
		}
	}
	return true;
}

bool Entity::removeChild(Entity* ent){
	for(int i = 0; i < children.size(); ++i){
		if(children[i] == ent){
			children.erase(children.begin()+i);
			return true;
		}
		if(children[i]->removeChild(ent)) return true;
	}
	return false;

}

Vector3 Entity::getPosition(){
	return getGlobalMatrix()*Vector3();
}

Matrix44 Entity::getGlobalMatrix(){
	if(parent){
		return model * parent->getGlobalMatrix();
	}
	return model;
}
